﻿using System;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
using DAL;
using BLL;
using System.Text;

public partial class Plublic_NonTermCurrent : System.Web.UI.Page
{

    string strConn = WebConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString();
    NonTermCurrentHandler objNonTermCurrentHandler = new NonTermCurrentHandler();
    LocationHandler objLocationHandler = new LocationHandler();
    UsersHandler objUsersHandler = new UsersHandler();
    InterestRatesHandler objInterestRatesHandler = new InterestRatesHandler();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindDropDowListAccHolders();
            this.BindDropDowListIRate();
            this.BindDropDowListLocation();
        }
    }

    protected void BindDropDowListAccHolders()
    {

        List<Users> lstUsers = new List<Users>();

        lstUsers = objUsersHandler.GetUsersList(strConn);

        ddlAccHolder.DataSource = lstUsers;
        ddlAccHolder.DataValueField = "UserID";
        ddlAccHolder.DataTextField = "FullName";
        ddlAccHolder.DataBind();

        
    }

    protected void BindDropDowListLocation()
    {
        List<Location> lstLocation = new List<Location>();

        lstLocation = objLocationHandler.GetLocationList(strConn);

        ddlLocation.DataSource = lstLocation;
        ddlLocation.DataValueField = "LocationID";
        ddlLocation.DataTextField = "Address";
        ddlLocation.DataBind();
    }

    protected void BindDropDowListIRate()
    {
        List<InterestRates> lstInterestRates = new List<InterestRates>();

        lstInterestRates = objInterestRatesHandler.GetInterestRatesList(strConn); ;

        ddlIRate.DataSource = lstInterestRates;
        ddlIRate.DataValueField = "InterestRatesID";
        ddlIRate.DataTextField = "InterestRate";
        ddlIRate.DataBind();
    }



    protected void calEventDate_SelectionChanged(object sender, EventArgs e)
    {
        txtOpenDate.Text = calEventDate.SelectedDate.ToString("MM/dd/yyyy hh:mm:ss");
    }
    protected void btnSave_Click(object sender, System.EventArgs e)
    {
        NonTermCurrent objNonTermCurrent = new NonTermCurrent();

        objNonTermCurrent.Created = DateTime.Now.ToString();
        objNonTermCurrent.Updated = DateTime.Now.ToString();
        objNonTermCurrent.Isactive = "1";
        objNonTermCurrent.AccountNumber = txtAccounNumber.Text.ToString();
        
        objNonTermCurrent.UserID = Convert.ToInt32(ddlAccHolder.SelectedValue);
        objNonTermCurrent.Opendate = txtOpenDate.Text.ToString();
        objNonTermCurrent.Balance = Convert.ToDouble(txtBalance.Text);
        
        objNonTermCurrent.Currency = ddlCurrency.Text.ToString();
        objNonTermCurrent.InterestRateID = Convert.ToInt32(ddlIRate.SelectedValue);
        objNonTermCurrent.LocationID = Convert.ToInt32(ddlLocation.SelectedValue);
        if (cboStatus.Checked == true)
        {
            objNonTermCurrent.Status = "1";
        }
        else
        {
            objNonTermCurrent.Status = "0";
        }
        objNonTermCurrent.AccountHolders = ddlAccHolder.SelectedItem.ToString();
        objNonTermCurrent.Descriptions = txtDescriptions.Text.ToString();


        if (objNonTermCurrentHandler.AddNewNonTermCurrent(objNonTermCurrent, strConn))
        {
            this.SetText();
        }
    }

    protected void SetText()
    {
        txtAccounNumber.Text = "";
        txtBalance.Text = "";
        txtDescriptions.Text = "";
        txtOpenDate.Text = "";
    }
    
}